﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using eStock.hControl;
using HCommon;

namespace eStock
{
    public partial class frmImExport_List : hForm
    {

        public frmImExport_List()
        {
            InitializeComponent();
            //this.QueryButton = btnFind;
        }

        private void frmImExport_List_Load(object sender, EventArgs e)
        {
            datFromDate.Value = DateTime.Now.AddMonths(-1);
            datToDate.Value = DateTime.Now;
            Common.LoadCombo(cboKind, "IEP", true);
            LoadGrid();
        }

        private void LoadGrid()
        {
            try
            {
                DataTable dt = new DataTable();
                dt = Dao.Get_Table("EXEC spImExport_Q N'" + txtImExportNo.Text + "',N'" + cboKind.SelectedValue.ToString() + "',N'" + txtItemCd.Text + "',N'" + txtCreateBy.Text + "',N'" + datFromDate.Value.ToString("yyyyMMdd") + "',N'" + datToDate.Value.ToString("yyyyMMdd") + "'");
                grdListImExport.DataSource = dt;
            }
            catch (Exception ex)
            {
                Common.GhiLog("LoadGrid", ex);
                Dialog.ShowMess(Dialog.mType.err, ex.Message);
            }

        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            LoadGrid();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            frmImExport imExport = new frmImExport();
            imExport.ShowDialog();
            if (imExport != null)
            {
                this.LoadGrid();
            }
        }

        private void grdListImExport_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (grdListImExport.Rows.Count >= 0)
                {
                    frmImExport imExport = new frmImExport();
                    imExport.ID = grdListImExport.Rows[e.RowIndex].Cells["ID"].Value.ToString();
                    imExport.ShowDialog();
                    if (imExport != null)
                    {
                        this.LoadGrid();
                    }
                }
            }
            catch (Exception ex)
            {
                Common.GhiLog("grdListImExport_CellDoubleClick", ex);
                Dialog.ShowMess(Dialog.mType.err, ex.Message);
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult ds = MessageBox.Show("Bạn có chắc chắn muốn xóa các giao dịch đã được chọn?", "Thông báo", MessageBoxButtons.YesNo);
                if (ds == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
                DataGridViewSelectedRowCollection lstRow = grdListImExport.SelectedRows;
                foreach (DataGridViewRow row in lstRow)
                {
                    string ImExportNo = row.Cells["ImExportNo"].Value.ToString();
                    //tblImExport.Exec("D", row.Cells["ID"].Value.ToString(), ref ImExportNo, "", "", "");
                }
                LoadGrid();
            }
            catch (Exception ex)
            {
                Common.GhiLog("btnDelete_Click", ex);
                Dialog.ShowMess(Dialog.mType.err, ex.Message);
            }
        }

    }
}
